package com.apeli.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.apeli.system.domain.vo.CommentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apeli.common.annotation.Log;
import com.apeli.common.core.controller.BaseController;
import com.apeli.common.core.domain.AjaxResult;
import com.apeli.common.enums.BusinessType;
import com.apeli.system.domain.Comment;
import com.apeli.system.service.CommentService;
import com.apeli.common.utils.poi.ExcelUtil;
import com.apeli.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author apeli
 * @date 2023-05-13
 */
@RestController
@RequestMapping("/system/comment")
public class CommentController extends BaseController
{
    @Autowired
    private CommentService commentService;

    /**
     * 查询
     */
    @GetMapping("/list")
    public TableDataInfo list(CommentVO commentVO)
    {
        startPage();
        List<CommentVO> list = commentService.listComment(commentVO);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @Log(title = "评论导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommentVO commentVO)
    {
        List<CommentVO> list = commentService.listComment(commentVO);
        ExcelUtil<CommentVO> util = new ExcelUtil<CommentVO>(CommentVO.class);
        util.exportExcel(response, list, "评论信息导出");
    }

    /**
     * 删除评论
     */
    @Log(title = "删除评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commentService.lambdaUpdate().in(Comment::getId,ids).remove());
    }
}
